#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
using namespace std;

const int N = 2020;

int original[N][N];
int rowMax[N][N];
int finalMax[N][N];

struct Node {
  int pos, val;
};

void slidingWindowMax(int src[N][N], int dst[N][N], int n,
                      int k, bool isRow) {
  for (int i = 1; i <= n; i++) {
    deque<Node> q;
    for (int j = 1; j <= n; j++) {
      int currRow = isRow ? i : j;
      int currCol = isRow ? j : i;

      // 移除超出窗口的元素
      if (!q.empty() && q.front().pos < j - k + 1)
        q.pop_front();

      // 维护队列单调性
      while (!q.empty() && src[currRow][currCol] >= q.back().val)
        q.pop_back();

      // 添加新元素
      q.push_back({j, src[currRow][currCol]});

      // 记录窗口最大值
      if (j >= k) {
        if (isRow)
          dst[currRow][currCol] = q.front().val;
        else
          dst[currCol][currRow] = q.front().val;
      }
    }
  }
}

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  // 读取输入数据
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &original[i][j]);

  // 横向处理
  slidingWindowMax(original, rowMax, n, k, true);

  // 纵向处理
  slidingWindowMax(rowMax, finalMax, n, k, false);

  // 输出结果
  for (int i = k; i <= n; i++) {
    for (int j = k; j <= n; j++)
      printf("%d ", finalMax[i][j]);
    printf("\n");
  }

  return 0;
}
